package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FBudget;
import com.ruoyi.system.service.IFBudgetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预算Controller
 * 
 * @author qi
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/budget")
public class FBudgetController extends BaseController
{
    @Autowired
    private IFBudgetService fBudgetService;

    /**
     * 查询预算列表
     */
    @PreAuthorize("@ss.hasPermi('system:budget:list')")
    @GetMapping("/list")
    public TableDataInfo list(FBudget fBudget)
    {
        startPage();
        List<FBudget> list = fBudgetService.selectFBudgetList(fBudget);
        return getDataTable(list);
    }

    /**
     * 导出预算列表
     */
    @PreAuthorize("@ss.hasPermi('system:budget:export')")
    @Log(title = "预算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FBudget fBudget)
    {
        List<FBudget> list = fBudgetService.selectFBudgetList(fBudget);
        ExcelUtil<FBudget> util = new ExcelUtil<FBudget>(FBudget.class);
        util.exportExcel(response, list, "预算数据");
    }

    /**
     * 获取预算详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:budget:query')")
    @GetMapping(value = "/{fBudgetid}")
    public AjaxResult getInfo(@PathVariable("fBudgetid") Long fBudgetid)
    {
        return success(fBudgetService.selectFBudgetByFBudgetid(fBudgetid));
    }

    /**
     * 新增预算
     */
    @PreAuthorize("@ss.hasPermi('system:budget:add')")
    @Log(title = "预算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FBudget fBudget)
    {
        return toAjax(fBudgetService.insertFBudget(fBudget));
    }

    /**
     * 修改预算
     */
    @PreAuthorize("@ss.hasPermi('system:budget:edit')")
    @Log(title = "预算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FBudget fBudget)
    {
        return toAjax(fBudgetService.updateFBudget(fBudget));
    }

    /**
     * 删除预算
     */
    @PreAuthorize("@ss.hasPermi('system:budget:remove')")
    @Log(title = "预算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fBudgetids}")
    public AjaxResult remove(@PathVariable Long[] fBudgetids)
    {
        return toAjax(fBudgetService.deleteFBudgetByFBudgetids(fBudgetids));
    }
}
